package com.graduation.smartparkingplatform.Controller;

import com.graduation.smartparkingplatform.Response.Response;
import com.graduation.smartparkingplatform.Response.ResponseUtils;
import com.graduation.smartparkingplatform.Utils.QRCodeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/QR")
public class QRCodeController {
  @GetMapping("/getQrCode")
  public Response createQrCode(@RequestParam("spaceId") String spaceId) {
    try {
      String base64 = QRCodeUtil.getBase64Image("space:spaceId=" + spaceId, null, true);
      return ResponseUtils.buildSuccess("200", "获取车位二维码成功", base64);
    } catch (Exception e) {
      log.error("getQrCode error-" + e);
      return ResponseUtils.buildBUSSINESS_ERROR(e);
    }
  }
}
